<template>
  <el-table :data="list" style="width: 100%;padding-top: 15px;">
    <el-table-column align="center" label="#" width="50">
      <template slot-scope="scope"><span>{{scope.row.px}}</span></template>
    </el-table-column>
    <el-table-column align="center" label="待办事项">
      <template slot-scope="scope">
        <span style="color: #cc0e7e; font-weight: bolder; ">
          {{ scope.row.groupName }}
        </span></template>
    </el-table-column>
    <el-table-column align="center" label="创建时间" min-width="100" prop="createdTime">
      <template slot-scope="scope"><span>{{scope.row.createdTime|timeFilter}}</span></template>
    </el-table-column>

    <el-table-column align="center" label="申请人" prop="operatorName">
      <template slot-scope="scope"><span>{{scope.row.operatorName}}</span></template>
    </el-table-column>
    <el-table-column align="center" label="待处理" prop="nodeName">
      <template slot-scope="scope">
        <el-tag style="cursor:pointer" @click="handleEdit(scope.row)" :type="scope.row.nodeId | statusFilter">{{
          scope.row.nodeName }}
        </el-tag>
      </template>
    </el-table-column>

    <!--    <el-table-column label="Price" width="195" align="center">
          <template slot-scope="scope">
            ¥{{ scope.row.price | toThousandFilter }}
          </template>
        </el-table-column>
        <el-table-column label="Status" width="100" align="center">
          <template slot-scope="scope">
            <el-tag :type="scope.row.status | statusFilter"> {{ scope.row.status }}</el-tag>
          </template>
        </el-table-column>-->
  </el-table>
</template>

<script>
  import {fetchGet} from '@/api/common'
  import {ERRS, SUCS} from '@/utils'

  export default {
    filters: {
      statusFilter(status) {
        const statusMap = {
          start_node: 'success',
          end_node: 'info',
          user_node: 'warning',
          // published: 'primary',
          // deleted: 'danger'
        }
        return statusMap[status]
      },
      timeFilter(str) {
        return str.substring(5, 16)
      }
    },

    props: {
      todoNum: {
        type: Number,
      },
    },
    data() {
      return {
        list: null
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      //审核
      handleEdit(row) {
        this.$router.push({name: row.groupId, params: row})
      },
      fetchData() {
        fetchGet(`flowable/ru/myTask?groupId=`).then(res => {
          if (res.code == 0) {
            let dat = res.data
            this.list = dat
            this.list = this.list.map((v, index) => {
              this.$set(v, 'px', index + 1);
              this.px = index + 1; //最大序号
              return v
            });
            this.$nextTick(() => {
              this.$emit('update:todoNum', this.list.length)
            })

          } else {
            ERRS(res.message)
          }
          this.listLoading = false
        })
      }
    }
  }
</script>
